home *** CD-ROM | disk | FTP | other *** search
/ Total Network Tools 2002 / NextStepPublishing-TotalNetworkTools2002-Win95.iso / Archive / Misc Servers / Hamster.EXE / htime.hsm < prev    next >
Encoding:
Text File  |  2000-04-29  |  4.0 KB  |  97 lines

  1. ########################################################################
  2. # Module     : htime.hsm
  3. # Description: Functions related with date and time.
  4. # Maintainer : Juergen Haible <juergen.haible@t-online.de>
  5. # Version    : 2000-04-29
  6. ########################################################################
  7. # NOTE:
  8. # This module is delivered with Hamster and it will be overwritten when
  9. # installing a new version of it. It might also be used by accompanying
  10. # demo-scripts, which depend on the current implementation.
  11. # So do NOT change this file unless you REALLY know what you do!
  12. ########################################################################
  13.  
  14. #!initialize
  15. debug( 255, "<<< module 'time.hsm' >>>" )
  16. return( 0 )
  17.  
  18. ########################################################################
  19. # DateTimeStr: Converts the given timepoint into a date/time-string
  20. ########################################################################
  21. # [IN]  $iDateTime: time in unix-format
  22. # [OUT] (result)  : string of format "YYYY-MM-DD HH:NN:SS"
  23. # Example: print( DateTimeStr( time ) )
  24.  
  25. sub DateTimeStr( $iDateTime )
  26.    return( DateStr($iDateTime) + " " + TimeStr($iDateTime) )
  27. endsub
  28.  
  29. ########################################################################
  30. # DateStr: Converts the given timepoint into a date-string
  31. ########################################################################
  32. # [IN]  $iDateTime: time in unix-format
  33. # [OUT] (result)  : string of format "YYYY-MM-DD"
  34. # Example: print( DateStr( time ) )
  35.  
  36. sub DateStr( $iDateTime )
  37.    var( $yyyy, $mm, $dd )
  38.    decodetime( $iDateTime, $yyyy, $mm, $dd )
  39.    return( str($yyyy,4) + "-" + str($mm,2) + "-" + str($dd,2) )
  40. endsub
  41.  
  42. ########################################################################
  43. # TimeStr: Converts the given timepoint into a time-string
  44. ########################################################################
  45. # [IN]  $iDateTime: time in unix-format
  46. # [OUT] (result)  : string of format "HH:NN:SS"
  47. # Example: print( TimeStr( time ) )
  48.  
  49. sub TimeStr( $iDateTime )
  50.    var( $hh, $nn, $ss )
  51.    decodetime( $iDateTime, 0, 0, 0, $hh, $nn, $ss )
  52.    return( str($hh,2) + ":" + str($nn,2) + ":" + str($ss,2) )
  53. endsub
  54.  
  55. ########################################################################
  56. # DayOfWeek: Returns the day of the week for a given timepoint.
  57. ########################################################################
  58. # [IN]  $iDateTime: time in unix-format
  59. # [OUT] (result)  : 1 (=Sunday), 2 (=Monday), ..., 7 (=Saturday)
  60. # Example: print( copy("SunMonTueWedThuFriSat",DayOfWeek(time)*3-2,3) )
  61.  
  62. sub DayOfWeek( $iDateTime )
  63.    var( $dow )
  64.    decodetime( $iDateTime, 0, 0, 0, 0, 0, 0, $dow )
  65.    return( $dow )
  66. endsub
  67.  
  68. ########################################################################
  69. # FormatDateTime: Converts the given timepoint into a formatted date-/
  70. #                 time-string.
  71. ########################################################################
  72. # [IN]  $iDateTime: time in unix-format
  73. #       $sFormat  : string containing placeholders for time-values:
  74. #                   "yyyy" (year, 4 digits), "yy" (year), "mm" (month),
  75. #                   "dd" (day), "hh" (hour), "nn" (minute), "ss" (sec.)
  76. # [OUT] (result)  : $sFormat with replaced date-/time-placeholders
  77. # Example: print( FormatDateTime( time, "mm-dd-yyyy hh.nn" ) )
  78.  
  79. sub FormatDateTime( $iDateTime, $sFormat )
  80.    var( $yyyy, $yy, $mm, $dd, $hh, $nn, $ss )
  81.    var( $dt, $i, $c )
  82.  
  83.    decodetime( $iDateTime, $yyyy, $mm, $dd, $hh, $nn, $ss )
  84.    $yy = $yyyy % 100
  85.  
  86.    $dt = $sFormat
  87.    $dt = replace( $dt, "yyyy", str($yyyy,4), true, true )
  88.    $dt = replace( $dt, "yy",   str($yy  ,2), true, true )
  89.    $dt = replace( $dt, "mm",   str($mm  ,2), true, true )
  90.    $dt = replace( $dt, "dd",   str($dd  ,2), true, true )
  91.    $dt = replace( $dt, "hh",   str($hh  ,2), true, true )
  92.    $dt = replace( $dt, "nn",   str($nn  ,2), true, true )
  93.    $dt = replace( $dt, "ss",   str($ss  ,2), true, true )
  94.  
  95.    return( $dt )
  96. endsub
  97.